<template>
  <div>
    <el-dialog ref="dialog" :title="$root.lang.control.device.detail.app.appSetting.title" :visible.sync="showDialog" width="35%" @close="closeDialog"  :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form @submit.native.prevent ref="form" size="small" label-position="right" label-width="110px" v-loading="init">
        <el-form-item>
          <el-checkbox-group v-model="appSettingList">
            <el-checkbox :label="setType.operateType[3].setType.startNow.name"></el-checkbox>
            <el-checkbox :label="setType.operateType[3].setType.autoStart.name"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item>
          <el-button class="dialog-btn"  type="primary" @click="onSubmit('form')">{{ $root.lang.control.device.detail.app.appSetting.confirm }}</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import '@/options/taskState';
export default {
  data() {
    return {
      init: false,
      loading: false,
      appSettingList: [],
      showDialog: this.show,
      appSettings: {
        startNow: 0,
        autoStart: 0,
      },
      setType: {}
    }
  },
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    show: function (value) {
      this.appSettingList = []
      this.appSettings = {
        startNow: 0,
        autoStart: 0,
      },
      this.showDialog = value
    },
  },
  methods: {
    closeDialog() {
      this.$emit('editReceive',{
        key: 'showEdit',
        value: this.showDialog
      })
    },
    checkLang() {
      let langType = this.$root.getStorage('lang')
      if(langType == 'en') {
        this.setType = enSetType
      } else {
        this.setType = setType
      }
    },
    onSubmit(formName) {
      if(this.appSettingList.length > 0) {
        this.appSettingList.forEach((item) => {
          if(item == this.setType.operateType[3].setType.startNow.name){
            this.appSettings.startNow = 1
          }else if(item == this.setType.operateType[3].setType.autoStart.name){
            this.appSettings.autoStart = 1
          }
        })
      } 
      this.$emit('reload', this.appSettings)
      this.showDialog = false
    },
  },
  created() {
    this.checkLang()
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">

</style>